<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2023/6/17
  Time: 16:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/9/24
  Time: 9:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>离线推荐</title>
</head>
<center>
    <div>
<%--<div  style="margin-left:500px;margin-top:50px;">--%>
    <body background="images\2.jpg";>
<%
    try {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:MySQL://localhost:3306/sakila?&useSSL=false&serverTimezone=UTC"; //指向数据库table
        String username = "root";  //数据库用户名
        String password = "123456";  //数据库用户密码
        Connection conn = DriverManager.getConnection(url, username, password);
        if(conn != null){
            out.print("数据库连接成功！");
            out.println("<br />");
            out.println("-------------------------------");
            out.print("<br />");
            Statement stmt = null;
            ResultSet rs = null;
            String sql ="select sid,name,score from student order by score desc limit 3";  //查询语句
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
            out.println("绩点前三学生名单:");
            out.println("<br />");
            out.println("-------------------------------");
            out.println("<br />");
            out.println("学号" + "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" + "姓名"+"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"+"绩点"+"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");
            out.println("<br />");
            while (rs.next()) {
                out.println(rs.getString("sid")+"   &nbsp  "+rs.getString("name")+"  &nbsp "+rs.getString("score")+"  &nbsp "); //将数据库表格查询结果输出
                out.print("<br />");
            }
        }
        else{
            out.print("连接失败！");
        }
    }
    catch (Exception e) {
        out.print("数据库连接异常！");
    }
%>
</body>
</div>
</center>
</html>

